package com.lemonPiggy.message.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.lemonPiggy.message.domain.MessageBase;
import com.lemonPiggy.message.service.IMessageBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 消息基础Controller
 * 
 * @author ruoyi
 * @date 2021-08-17
 */
@RestController
@RequestMapping("/base")
public class MessageBaseController extends BaseController
{
    @Autowired
    private IMessageBaseService messageBaseService;

    /**
     * 查询消息基础列表
     */
    @PreAuthorize(hasPermi = "system:base:list")
    @GetMapping("/list")
    public TableDataInfo list(MessageBase messageBase)
    {
        startPage();
        List<MessageBase> list = messageBaseService.selectMessageBaseList(messageBase);
        return getDataTable(list);
    }

    /**
     * 导出消息基础列表
     */
    @PreAuthorize(hasPermi = "system:base:export")
    @Log(title = "消息基础", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MessageBase messageBase) throws IOException
    {
        List<MessageBase> list = messageBaseService.selectMessageBaseList(messageBase);
        ExcelUtil<MessageBase> util = new ExcelUtil<MessageBase>(MessageBase.class);
        util.exportExcel(response, list, "消息基础数据");
    }

    /**
     * 获取消息基础详细信息
     */
    @PreAuthorize(hasPermi = "system:base:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(messageBaseService.selectMessageBaseById(id));
    }

    /**
     * 新增消息基础
     */
    @PreAuthorize(hasPermi = "system:base:add")
    @Log(title = "消息基础", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MessageBase messageBase)
    {
        return toAjax(messageBaseService.insertMessageBase(messageBase));
    }

    /**
     * 修改消息基础
     */
    @PreAuthorize(hasPermi = "system:base:edit")
    @Log(title = "消息基础", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MessageBase messageBase)
    {
        return toAjax(messageBaseService.updateMessageBase(messageBase));
    }

    /**
     * 删除消息基础
     */
    @PreAuthorize(hasPermi = "system:base:remove")
    @Log(title = "消息基础", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(messageBaseService.deleteMessageBaseByIds(ids));
    }
}
